import { Component, OnInit, ViewChild } from '@angular/core';
import { _HttpClient } from '@delon/theme';
import { TableComponent } from './table.component';
import { environment } from '../../../../environments/environment';
import { LocalStorage } from '@core/local.storage';
import { FarmReactComponent } from '../../../layout/components/farmreact.component';

@Component({
    selector: 'app-cableroute',
    templateUrl: './cableRoute.component.html',
    styleUrls: ['./cableRoute.component.less']
})

export class CableRouteComponent implements OnInit {
    @ViewChild('tcp', { static: true }) tcp: TableComponent;
    @ViewChild('farmReact', { static: false }) farmReact: FarmReactComponent;
    searchParam: any = {};
    apiUrl: any = {};
    headData = [];
    plainData = [];
    tempData = [];
    operaList: any = [
        { addModal: false },
        { editModal: false },
        { delModal: false }
    ];
    userId = JSON.parse(this.ls.get('loginInfo')).VC_NUMBER;
    typeName = window.location.href.split('/')[window.location.href.split('/').length - 1];

    constructor(
        public ls: LocalStorage,
        public http: _HttpClient
    ) { }

    ngOnInit() {
        this.headData = [
            { "name": "线别", "width": "10%" },
            { "name": "车间", "width": "10%" },
            { "name": "工区", "width": "10%" },
            { "name": "车站", "width": "10%" },
            { "name": "图纸附件", "width": "12%" },

            { "name": "创建时间", "width": "10%" },
            { "name": "备注", "width": "" },
            { "name": "上传工区名称", "width": "10%" },
            { "name": "上传日期", "width": "10%" }
        ];
        this.plainData = [
            "lineType", "wsOrgName", "waOrgName", "stationName", "drawingName",
            "createTimeFormat", "breaks", "upLoadOrgName", "uploadDateFormat"
        ];
        this.apiUrl.add = environment.devscore + '/sysTCable/add';
        this.apiUrl.edit = environment.devscore + '/sysTCable/update';
        this.apiUrl.del = environment.devscore + '/sysTCable/delete';
        this.loadList();
    }
    loadList() {
        this.tcp.loadList(environment.devscore + '/sysTCable/query', '');
    }
    search() {
        let params = '';
        if (this.searchParam.drawingName) {
            params += '&drawingName=' + this.searchParam.drawingName;
        }
        this.farmReact.childOuter((res) => {
            if (res.chejianValue !== '0') {
                params += '&wsOrgId=' + (res.chejianValue || '');
            }
            if (res.gongquValue !== '0') {
                params += '&waOrgId=' + (res.gongquValue || '');
            }
            if (res.chezhanValue !== '0') {
                params += '&stationId=' + (res.chezhanValue || '');
            }
        });
        this.tcp.loadList(environment.devscore + '/sysTCable/query', params);
    }
    modalShow(type) {
        this.tempData = this.tcp.getAllData();
        this.operaList[type] = true;
    }
    modalHide(type) {
        this.operaList[type] = false;
    }
}
